package com.photography.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.photography.pojo.Order;
import com.photography.pojo.Serial;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface OrderMapper extends BaseMapper<Order> {

    @Insert("INSERT INTO serial_order (`serialid`, `orderid`) VALUES(#{serialid}, #{orderid})")
    void addSerialIdAndOrderId(@Param("serialid") String serialid, @Param("orderid")String orderid);

    @Insert("INSERT INTO product_order (`productid`, `orderid`) VALUES(#{productid}, #{orderid})")
    void addProductIdAndOrderId(@Param("productid") String productid, @Param("orderid")String orderid);

    @Select("SELECT * FROM tb_order WHERE customerid = #{customerId}")
    List<Order> selectByCustomerId(String customerId);

    @Select("SELECT * FROM tb_order WHERE appointmenttime >= #{startTime} AND appointmenttime <= #{endTime} ORDER BY appointmenttime ASC")
    List<Order> selectByStartTimeAndEndTime(@Param("startTime") String startTime,@Param("endTime")String endTime);

    @Select("SELECT serialid FROM serial_order WHERE orderid = #{OrderId}")
    List<String> selectSerialIdByOrderId(String OrderId);

    @Select("SELECT productid FROM product_order WHERE orderid = #{OrderId}")
    List<String> selectProductIdByOrderId(String OrderId);

    @Delete("DELETE FROM serial_order WHERE orderid= #{OrderId}" )
    void deleteSerialIdsByOrderId(String OrderId);

    @Delete("DELETE FROM product_order WHERE orderid= #{OrderId}")
    void deleteProductIdsByOrderId(String id);

}
